package project.parser.ast.stats;

import project.environments.DynamicEnv;
import project.environments.StaticEnv;
import project.parser.ast.aux.Stats;

import static project.parser.tokenizer.TokenType.CLOSED_CURLY;
import static project.parser.tokenizer.TokenType.OPEN_CURLY;

public class Block implements Stat {

	private final Stats stats;

	public Block(Stats stats) {
		this.stats = stats;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder().append(OPEN_CURLY);
		sb.append(stats.toString());
		sb.append(CLOSED_CURLY);
		return sb.toString();
	}

	@Override
	public void typecheck(StaticEnv senv) {
		senv.enterScope();
		stats.typecheckList(senv);
		senv.exitScope();
	}

	@Override
	public void evaluate(DynamicEnv denv) {
		denv.enterScope();
		stats.evaluateList(denv);
		denv.exitScope();
	}
}
